

;
; file: skel.asm
; This file is a skeleton that can be used to start assembly programs.

%include "asm_io.inc"
segment .data
;
; initialized data is put in the data segment here
;
msg1	dw	"Give 1st char: ",0
msg2	dw	"Give 2nd char: ",0
msg3	dw	"Give 3rd char: ",0
msg4	dw	"Give 4th char: ",0
msg5	dw	"Give 5th char: ",0
sep	dw	",",0

segment .bss
;
; uninitialized data is put in the bss segment
;
array 	resw 5
msg	resw 5
 

segment .text
        global  asm_main
asm_main:
        enter   0,0               ; setup routine
        pusha
	push	ebx

;	program start

	mov dword[msg],msg1
	mov dword[msg+4],msg2
	mov dword[msg+8],msg3
	mov dword[msg+12],msg4
	mov dword[msg+16],msg5

	mov 	ecx, 5
	mov 	ebx, array
	mov 	esi, msg
input_loop:
	mov	eax, [esi]
	call 	print_string
test:
	call 	read_char
	cmp	eax, 10
	jz	test	
	mov 	[ebx],eax
	add 	ebx, 4
	add 	esi, 4
	loop	input_loop

	mov 	ecx, 5
	sub 	ebx, 4
output_loop:
	mov 	eax, [ebx]
	sub 	ebx, 4
	call 	print_char
	cmp	ecx,1
	jz	exit
	mov	eax, sep
	call 	print_string
	loop 	output_loop

exit:
	call	print_nl
;	program stop
	
	pop	ebx
        popa
        mov     eax, 0            ; return back to C
        leave                     
        ret


